home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / game / shoot / Orbit_src.lha / Orbit / source / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-04  |  1.6 KB  |  84 lines

  1. /*
  2.     Amiga port by Oliver Gantert
  3.  
  4.     27.04.2000 - fixed some compiler warnings
  5. */
  6. /*
  7.  
  8. ORBIT, a freeware space combat simulator
  9. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  24.  
  25. */
  26.  
  27. #include "orbit.h"
  28. #include <stdarg.h>
  29.  
  30. /*
  31.  *  Stuff to maintain the log file
  32.  */
  33.  
  34. FILE *logfd;
  35.  
  36. void InitLog()
  37. /*
  38.  *  Open the log file
  39.  */
  40. {
  41.   if (NULL == (logfd = fopen ("orbit.log", "wt"))) return;
  42.  
  43.   Log ("InitLog()");
  44. }
  45.  
  46. void CloseLog()
  47. /*
  48.  *  Close up the log file
  49.  */
  50. {
  51.   Log ("CloseLog()");
  52.   fclose (logfd);
  53. }
  54.  
  55. void Log (char *fmt, ...)
  56. /*
  57.  *  Write a log message
  58.  */
  59. {
  60.   va_list ap;
  61.   int tm;
  62.   char buf[64];
  63.  
  64.   tm = time (NULL);
  65.  
  66.   va_start (ap, fmt);
  67.   strcpy (buf, ctime((const time_t *)&tm));
  68.   buf[strlen(buf)-1] = 0;
  69.   fprintf (logfd, "%s: ", buf);
  70.   vfprintf (logfd, fmt, ap);
  71.   fprintf (logfd, "\n");
  72.   fflush (logfd);
  73.   va_end (ap);
  74. }
  75.  
  76. void LogWrite (char *buf, int n)
  77. /*
  78.  *  Write raw data to logfile
  79.  */
  80. {
  81.   fwrite (buf, 1, n, logfd);
  82.   fprintf (logfd, "\n");
  83. }
  84.